
import axios from "axios";
import router from '../router/index'
import { message } from 'ant-design-vue'
let baseURL
if (process.env.NODE_ENV === 'development') {
  baseURL = '/api'
} else {
  baseURL = '/api' //mock模拟数据
}
let instance = axios.create({
  baseURL: baseURL,
  timeout: 1500 //毫秒
})


/**
 * 请求拦截
 */
instance.interceptors.request.use(config => {
  return config
}, err => {
  return Promise.reject(err)
})

/**
 * 响应拦截
 */

instance.interceptors.response.use(res => {
  if (res.data.code == '1018') {
    message.error('登录失效,请重新登录~')
    router.push('/login')
  }
  if (res.data.code === 200) {
    return Promise.resolve(res.data.data)
  } else {
    return Promise.reject(res.data)
  }

}, err => {
  return Promise.reject(err)
})


export default instance

